package sliding_window;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: 86185
 * Date: 2023-12-04
 * Time: 16:29
 */
public class LongestOnes {
    public static int longestOnes(int[] nums, int k) {
        int ans = 0;
        int count = 0;
        for(int right = 0, left = 0; right < nums.length; right++) {
            if(nums[right] == 0) {
                count++;
            }
            while(count > k) {
                if(nums[left] == 0) {
                    count--;
                }
                left++;
            }
            ans = Math.max(ans, right - left + 1);
        }
        return ans;
    }

    public static void main(String[] args) {
        longestOnes(new int[]{1,1,1,0,0,0,1,1,1,1,0}, 2);
    }
}
